package top.codedance.iotp.iot.sdk.entity;

import com.alibaba.fastjson.JSONObject;

public class HttpCommandEntity {
    public static enum Method {
        get, post, delete, put, patch, head, option;
    };

    public static enum Protocol {
        http, https;
    };

    private Method method;
    private Protocol protocol;
    private String url;
    private String requestBody;
    private HttpHeaders headers;

    public Method getMethod() {
        return method;
    }

    public void setMethod(Method method) {
        this.method = method;
    }

    public Protocol getProtocol() {
        return protocol;
    }

    public void setProtocol(Protocol protocol) {
        this.protocol = protocol;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getRequestBody() {
        return requestBody;
    }

    public void setRequestBody(String requestBody) {
        this.requestBody = requestBody;
    }

    public HttpHeaders getHeaders() {
        return headers;
    }

    public void setHeaders(HttpHeaders headers) {
        this.headers = headers;
    }

    public static HttpCommandEntity.Method methodValueOf(String method){
        method = method.toLowerCase();
        if(method.equals(Method.get.toString())){
            return Method.get;
        }
        if(method.equals(Method.post.toString())){
            return Method.post;
        }
        if(method.equals(Method.delete.toString())){
            return Method.delete;
        }
        if(method.equals(Method.put.toString())){
            return Method.put;
        }
        if(method.equals(Method.patch.toString())){
            return Method.patch;
        }
        if(method.equals(Method.head.toString())){
            return Method.head;
        }
        if(method.equals(Method.option.toString())){
            return Method.option;
        }
        return null;
    }

    public static HttpCommandEntity.Protocol protocolValueOf(String protocol){
        protocol = protocol.toLowerCase();
        if(protocol.equals(Protocol.http.toString())){
            return Protocol.http;
        }
        if(protocol.equals(Protocol.https.toString())){
            return Protocol.https;
        }
        return null;
    }
}
